Skip to main content

OCR - Azure AI Document Intelligence

ACCESS THE CUSTOM STEP FOLDER

This custom step was previously known as 'OCR - Azure AI Document Intelligence Table Extraction'

This custom step uses the Azure AI Document Intelligence service to perform different types of OCR on files that are stored on the SAS file system. What is Azure AI Document Intelligence?

✨ Features​

  • ✅ Text Extraction (words / lines / paragraphs / pages / document)
  • ✅ Form Extraction (key-value pairs)
  • ✅ Query Extraction (extraction of specified keys)
  • ✅ Table Extraction
  • ✅ Local Container Support

📖 Contents​

💻 User Interface​

  • Settings tab​

    Standalone modeFlow mode
  • Azure Settings tab​

  • Azure connection tab​

  • Advanced settings tab​

  • About tab​

Note: if there are no links shown under Documentation, then ask your SAS administrator to go into SAS Environment manager and use the Configuration panel to configure the allowedStepLinks option of the Data Flow service to allow https connections. You can learn more in this SAS community article.

👩‍💻 Usage​

📺 Tutorial (👇Click Thumbnail👇)​

YOUTUBE THUMBNAIL

Note: This step works great with the Create Listings of Directory - CLOD custom step to create the input file-list based on a folder of documents.

Feature Matrix​

File FormatsOCR Processing
ExtractionPDFImage1URLAzure2Local Container3,4
Text✅✅✅✅✅
Form✅✅✅✅✅
Query✅✅✅✅
Table✅✅✅✅✅

$^1$ JPEG/JPG, PNG, BMP, TIFF, HEIF | $^2$ API-Version 2023-10-31-preview (4.0) | $^3$ API-Version 2022-08-31 (3.0)
$^4$ Only supports General Document Model / Container

Test data​

Pro Tip: Take a photo with your smartphone, make a screenshot of a document or export a PowerPoint slide as image / PDF.

📋 Requirements​

Tested on SAS Viya version Stable 2024.02

🐍 Python​

📦 Packages​

🤖 Azure AI Document Intelligence Resource​

To use this step the endpoint and key for an Azure Document Intelligence Resource is needed. 👉 Create a Document Intelligence resource

⚙️ Settings​

General​

ParameterRequiredDescription
OCR TypeYesDefines the type of Optical Character Recognition (OCR) to use
Input ModeYesIndicates if processing a list of files or a single file
Input TypeYesIndicates if local documents or document URLs are used as input
File PathNo*The file path for processing a single file
Input TableNo†The name of the table containing file paths/URLs for batch processing
Path ColumnNo†The column in the input table that contains the file path/URL

* Required if Input Mode is set to "single".
† Required if Input Mode is set to "batch".

Text Settings
ParameterRequiredDescription
GranularityYesDefines granularity of the text output (e.g. word, line, paragrpah, page). Has implications regarding extraction output (e.g. 'role' only for paragraphs, 'confidence' only for words/pages)
  • word - includes confidence value
  • line - text line per row
  • paragraph - blocks of text, can include 'role' of a given paragraph (heading, etc..)
  • page - everything one one page
  • document - everything in the document
Query Settings
ParameterRequiredDescription
Query FieldsYesList of keys that are used as queries in the extraction process.
Exclude MetadataNoIf set to 'yes', all meta information from the extraction will be ignored, and the output will only contain a column per key and a row per file.
Table Settings
ParameterRequiredDescription
Table Output FormatYesDefines the output format for table extraction:
  • map - outputs (col_id, row_id, value) for later reconstruction
  • reference - outputs a row per table with a uuid as reference, stored in the defined library
  • table - outputs one table through standard output, supports only one table and one file
Table Output LibraryNo*Defines the output library for extracted. tables
Select TablesNo†Defines if a table per document is selected.
Table Selection MethodNoDefines the method to select the table per document that is extracted:
  • index - uses the index to select the extracted table.
  • size - selects the table with the most cells.
Table IndexNo‡Table index to extract.

* Only available if Table Output Format is set to "reference".
† Defaults to true when Table Output Format is "table".
‡ Required if Table Selection Method is set to "index"

🔐 Azure​

ParameterRequiredDescription
Endpoint URLYesAI Document Intelligence Resource Endpoint
KeyYesSecret Key
Local ContainerNoWhether or not to use a locally deployed Document Intelligence container. Please make sure to deploy the General Document container.
Container EndpointNo*URL and Port of the locally deployed container.

* Required if Local Container is set to True.

👉Where to find resource key and endpoint

🧙‍♂️ Advanced​

ParameterRequiredDescription
Force LanguageNoOption to force Document Intelligence to use only a specific language for OCR. Note: Languages are detected automatically by default.
Timeout†NoHow many seconds to wait for the OCR process to finish for document before timing out.
Number of RetriesNoHow many retries attempts before a document is skipped
Seconds between retriesNoHow many seconds between retry attempts
Number of ThreadsNoHow many Python threads will be used to process all files.
Save as JSONNoWhether to save the raw output as JSON (one file per document)
Output FolderNo*Folder for the JSON files.

† Note: Make sure to set this high enough if your documents are excessively large.
* Required if Save as JSON is set to true.

📚 Documentation​

📝 Change Log​

Version 2.0 (22MAR2024)

  • Renamed to "OCR - Azure AI Document Intelligence"
  • Added support for text, form and query extraction
  • Added support for extracting multiple tables at once
  • Added support for processing multiple files at once
  • Added support for local document intelligence container
  • Added option to output status table
  • Added multithreading
  • Upgraded used API version to Document Intelligence 4.0

Version 1.0 (02JAN2024)

  • Initial Version